const fp = require('lodash/fp')
const {Maybe,Container} = require('./support')


//题目1
let maybe = Maybe.of([5,6,1])
let add = n=> fp.add(n,1)
let fn = value => fp.map(add,value)
let ex1 = () =>{
    maybe = maybe.map(fn)
    console.log(maybe)
}
ex1()

//题目2
let arr = ['do','ray','me','fa','so','la','ti','do']
let xs = Container.of(arr)
let fn2 = arr => fp.first(arr)
let ex2 = () => xs.map(fn2)._value
console.log(ex2())

//题目3
let safeProp = fp.curry(function(x,o){
    return Maybe.of(o[x])
})
let user = {id:2,name:'Albert'}
let ex3 = () => str = fp.first(safeProp('name',user)._value)
console.log(ex3())

//题目4
let ex4 = function(n) {
    let may = Maybe.of(n)
    return may.map(parseInt)._value
}
let ex5 = function(n){
    if(n){
        return parseInt(n)
    }
}
console.log(ex4(1))
console.log(ex5(1))
console.log(ex4(undefined))
console.log(ex5(undefined))//比较与原函数的区别